package com.safe.controller.api;

import com.safe.core.bean.Result;
import com.safe.entity.Trajectory;
import com.safe.service.TrajectoryService;
import com.safe.utils.JsonUtil;
import com.safe.utils.WebUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * IndexApi
 * Created by Administrator on 2020/6/15.
 */
@Controller
@RequestMapping(value = "api/money")
public class IndexApi {

    @Autowired
    private TrajectoryService trajectoryService;

    /**
     * @api {post} /api/money/recordList   1、查询设备轨迹列表
     * @apiVersion 0.0.1
     * @apiName recordList
     * @apiGroup money
     *
     * @apiDescription 查询设备轨迹列表
     *
     * @apiParam   {Integer}   typeId                         类别ID
     * @apiParam   {Integer}   status                         类型
     * @apiParam   {Long}      startTime                      起始时间
     * @apiParam   {Long}      endTime                        截止时间
     *
     * @apiSuccess {Object}    list
     * @apiSuccess {Integer}   list.id                        流水记录ID
     * @apiSuccess {Object}    list.type                      类别
     * @apiSuccess {String}    list.type.id                   类别ID
     * @apiSuccess {String}    list.type.name                 类别名称
     * @apiSuccess {Double}    list.money                     金额
     * @apiSuccess {Integer}   list.status                    类别，0=支出，1=收入
     * @apiSuccess {Long}      list.createTime                记录时间
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "code":0,
     *      "msg":"",
     *      "data":{[
     *          {
     *              "id" : 1,
     *              "type" : {
     *                  "id": 1,
     *                  "name": "吃饭"
     *              },
     *              "money" : 11.00,
     *              "status" : 0,
     *              "createTime" : "1530754884328"
     *          },
     *          {
     *              "id" : 2,
     *              "type" : {
     *                  "id": 2,
     *                  "name": "交通"
     *              },
     *              "money" : 3.00,
     *              "status" : 0,
     *              "createTime" : "1530754884328"
     *          }
     *      ]
     * }
     */
    @RequestMapping(value = "/recordList", method = RequestMethod.POST)
    @ResponseBody
    public void recordList(HttpServletResponse response,
                           Integer typeId,
                           Integer status,
                           String startTime,
                           String endTime) {
        List<Trajectory> list = trajectoryService.findAll();

        String result = JsonUtil.obj2ApiJson(Result.successApi(list), "content");
        WebUtil.printApi(response, result);
    }
}
